package com.example.vspm.service.impl;

import com.example.vspm.entity.TaskForm;
import com.example.vspm.mapper.TaskFormMapper;
import com.example.vspm.service.TaskFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author LCL
 * @date 2022/3/8
 * @desc
 */
@Service
public class TaskFormServiceImpl implements TaskFormService {
    @Autowired
    TaskFormMapper taskFormMapper;
    @Autowired
    HttpServletRequest request;//通过注解获取一个request,获取session


    //添加工单//////////////
    public void addTaskForm(TaskForm taskForm){
        taskFormMapper.addTaskForm(taskForm);
//        //获取自增工单的id,方便下面   ,第二种使用session
//        System.out.println(taskForm.getTid());
//        //获取自增,添加的工单id
//        //往工单里添加pid1
//        Object object = request.getSession().getAttribute("person");
//        Person person = (Person)object;
//        System.out.println(person.getTid()+person.getPersonName());
//        addTaskFormPID1(person.getTid(),taskForm.getTid());
//        session.setAttribute("addTaskForm",taskForm);
//        //获取存放在session中的工单id
////        Object object1 = request.getSession().getAttribute("TaskForm");
////        TaskForm taskForm1 = (TaskForm) object1;
////        System.out.println("这是存放在session的工单id"+taskForm1.getTid());

    }

    //添加工单的pid1
        public void addTaskFormPID1(int pid1,int taid){
            taskFormMapper.addTaskFormPID1(pid1,taid);
        }

    //根据前端中的工单id更新工单状态
    @Override
    public void updateState(String state, int tid) {
        taskFormMapper.updateState(state,tid);
    }


    //查看总工单//////////////////////////////////////////
    //报单员根据session中的person id 查看工单
    public List<TaskForm> listTaskFormByPid1(int pid1){
        return taskFormMapper.listTaskFormByPid1(pid1);
    };
    //接单员根据session中的person id 查看工单
    public List<TaskForm> listTaskFormByPid3(int pid3){
        return taskFormMapper.listTaskFormByPid3(pid3);
    };
    //派单员查看所有工单
    public List<TaskForm> listTaskForm(){
        return  taskFormMapper.listTaskForm();
    };

    //根据工单ID查看工单详情页,方便显示会场以及接单人员的挑选
    @Override
    public List<TaskForm> listTaskFormByTid(int tid) {
        return taskFormMapper.listTaskFormByTID(tid);
    }


    ////////////////////////挑选接单员
    ////在挑选接单员的时候,根据前端传来的pid3录入到工单表中
    @Override
    public void addTaskFormPID3(int pid3, int tid) {
        taskFormMapper.addTaskFormPID3(pid3,tid);
    }

    @Override
    public void updateTaskFormPID3(int pid3, int tid) {
     taskFormMapper.updateTaskFormPID3(pid3,tid);
    }

    //删除工单
    public  void deleteTaskForm(int tid){
        taskFormMapper.deleteTaskForm(tid);
    }


}
